package com.cz.spb_activiti;

import org.activiti.engine.RepositoryService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@MapperScan("com.cz.spb_activiti.mapper")
public class SpbActivitiApplication implements ApplicationRunner {
    @Autowired
    RepositoryService repositoryService;

    public static void main(String[] args) {
        SpringApplication.run(SpbActivitiApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        if (repositoryService.createDeploymentQuery().deploymentName("demandProcessBPMN").list().size() == 0)
            repositoryService.createDeployment()
                    .addClasspathResource("activiti/demand.bpmn20.xml").name("demandProcessBPMN").deploy();
    }
}
